package TankGame;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

// 开始面板
class StartPanel extends JPanel {
    private TankGame tankGame;

    public StartPanel(TankGame tankGame) {
        this.tankGame = tankGame;
        setBackground(Color.DARK_GRAY); // 设置背景为灰色
        setLayout(new GridBagLayout());

        // 添加标题
        JLabel titleLabel = new JLabel("坦克大战");
        titleLabel.setFont(new Font("楷书", Font.BOLD, 54));
        titleLabel.setForeground(Color.WHITE);
        titleLabel.setHorizontalAlignment(SwingConstants.CENTER);

        JButton startButton = new JButton("开始游戏");
        startButton.setFont(new Font("仿宋体", Font.BOLD, 24));
        startButton.setForeground(Color.WHITE);
        startButton.setBackground(Color.GRAY);
        startButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                tankGame.startGame();
            }
        });

        JButton exitButton = new JButton("退出游戏");
        exitButton.setFont(new Font("仿宋体", Font.BOLD, 24));
        exitButton.setForeground(Color.WHITE);
        exitButton.setBackground(Color.GRAY);
        exitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });

        GridBagConstraints gbc = new GridBagConstraints();

        // 添加标题
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 1;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.insets = new Insets(20, 0, 80, 0); // 减少顶部间距，增加底部间距
        add(titleLabel, gbc);

        // 添加开始按钮
        gbc.gridy = 1;
        gbc.insets = new Insets(0, 0, 0, 0); // 去掉顶部间距
        add(startButton, gbc);

        // 添加退出按钮
        gbc.gridy = 2;
        gbc.insets = new Insets(30, 0, 0, 0); // 增加顶部间距
        add(exitButton, gbc);
    }
}
